package 进阶.线程.线程安全.demo02同步代码;

public class RunnaleImpl implements Runnable {


    //创建锁对象
    Object obj = new Object();


    private int t = 1000;
    @Override
    public void run() {

        while (true){
           show();
        }
    }


    //同步方法
    public synchronized void show(){
        if(t > 0){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("卖出了第"+ t + "张票");
            t --;
            System.out.println(Thread.currentThread().getName());
        }
    }
}
